package webDevelopment.util;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;

/**
 * 打印日志的文件
 */
public class Log {
    public static void println(Object o) {
        LocalDateTime localDateTime = LocalDateTime.now(ZoneId.of("Asia/Shanghai"));

        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

        String now = formatter.format(localDateTime);

        Thread thread = Thread.currentThread(); // 获取当前线程

        String message = String.format("%s (%d:%s): %s", now, thread.getId(), thread.getName(), (o == null ? "null" : o.toString()));    // 类似于 System.out.printf，区别是不打印，而是变成字符串返回

        System.out.println(message);
    }

    public static void main(String[] args) {
        println(1);
    }
}
